package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;


import com.sky.result.Result;
import com.sky.service.admin.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {
    @Autowired
    private DishService dishService;


    @GetMapping("/page")

    @ApiOperation("分页查询")
    public Result pageQuery(DishPageQueryDTO dishPageQueryDTO){
        log.info("分页查询菜品信息：{}",dishPageQueryDTO);
        PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
        return Result.success(pageResult);


    }
    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dishDTO){
        log.info("新增菜品：{}",dishDTO);
        Result result = dishService.addDish(dishDTO);
        return result;
    }
    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result deleteByIds(@RequestParam("ids") Long[] ids){
        log.info("批量删除菜品：{}",ids);
        Result result = dishService.deleteByIds(ids);
        return result;
    }
    @GetMapping("/{dishId}")
    @ApiOperation("根据id查询菜品")
    public Result getById(@PathVariable Long dishId){
        log.info("根据id查询菜品：{}",dishId);
        Result result = dishService.getById(dishId);
        return result;
    }
    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDish(@RequestBody DishDTO dishDTO){
        log.info("修改菜品：{}",dishDTO);
        Result result = dishService.updateDish(dishDTO);
        return result;
    }
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品,用于往套餐里面加菜品")
    public Result findByCategoryId(Long categoryId){
        Result byCategoryId = dishService.findByCategoryId(categoryId);
        return byCategoryId;

    }
    @PostMapping("/status/{status}")
    @ApiOperation("起售停售")
    public Result startOrStop(@PathVariable Long status,@RequestParam("id") Long id){
        dishService.startOrStop(status,id);
        return Result.success();
    }



}
